from model.Hero import Hero
from model.events.Event import Event
from view.blockImgs.EventImg import EventImg


class Door(Event):
    dic = {"yellow": "黃", "purple": "藍", "red": "紅"}

    def __init__(self, x_position, y_position, color):
        Event.__init__(self, x_position, y_position)
        self.img_path = "resources/地形/門/" + Door.dic[color] + " 0.png"
        self.img = EventImg(self, x_position, y_position)
        self.color = color
        self.isOpening = False
        self.isWork = True
        self.open_step = 0;

    def trigger(self):
        Hero.direction = [0, 0, Hero.direction[2]]
        Hero.step = Hero.step % 4
        if self.color == "yellow" and Hero.yellowKey > 0:
            Hero.yellowKey -= 1
            self.disappear()
        elif self.color == "purple" and Hero.purpleKey > 0:
            Hero.purpleKey -= 1
            self.disappear()
        elif self.color == "red" and Hero.redKey > 0:
            Hero.redKey -= 1
            self.disappear()

    def disappear(self):
        self.isOpening = True
        self.isWork = False

    def update(self):
        if self.isOpening and self.open_step < 15:
            self.open_step += 1
            print(self.open_step // 4)
            self.img_path = "resources/地形/門/" + Door.dic[self.color] + " %s.png" % (self.open_step // 4)
        elif self.isOpening and self.open_step >= 15:
            self.img_path = "resources/素材/magic_attack0 3.png"
